/*
 * This file is part of SSHTTPD.
 *
 * SSHTTPD is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * SSHTTPD is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _FILE_H
#define _FILE_H

/** @file
 * Defines global structures and functions implemented and used by file.c.
 */

/** Holds a files contents aswell as various meta-data gathered from it. */
typedef struct metafile {
	/** Data retreived from disk. */
	char *data; 	
	/** Content-type of the file. */
	char *ctype; 	
	/** Size of the file. */
	int size; 	
	/** True if the file has not been found. */
	int nf; 
} mfile_t;

/**
 * Creates a new metafile structure out of the values given instead of 
 * retreiving anything from disk. 
 * @param data Data to store int he file, is copied.
 * @param ctype Content-type of the file. also copied.
 * @param size Size of the data part of the metafile.
 * @return A new metafile object, needs to be destroyed.
 */
mfile_t *newfile(char *data, char *ctype, int size); 

/**
 * Destroys a metafile structure.
 * @param file metafile to destroy.
 */
void destroyfile(mfile_t *file);

/**
 * Gets a file from disk and stores it in a metafile structure.
 * @param url File to retreive from disk, ie /index.html.
 * @param pretend Get the file metadata but not the data from disk.
 * @return Metafile structure, must be destroyed.
 */
mfile_t *getfile(const char *url, int pretend);

#endif
